-- open_grid_reduce
-- created by xinj
-- 开启x块石板后，x属性减少100%

return {
    apply = function(prop, baseValue)
        return baseValue - prop[3];
    end,

    -- 每回合触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return 0;
        end

        if type(arg) ~= "number" then
            return 0;
        end

        local openGrid = 0;
        -- 统计开过的格子
        for p = 1, DUNGEON_WIDTH * DUNGEON_HEIGHT do
            local grid = DungeonM.getGridByPos(p);

            if grid:isOpened() then
                openGrid = openGrid + 1;
            end
        end

        if openGrid < prop[3] then
            return arg;
        end

        return 0;
    end,

    record = function(target, prop, path)
        return false;
    end
};